package bookExercise;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class A16Filter {
    public static void main(String[] args) {
        List<Integer> a =new ArrayList<>();
        for(int i =0 ;i<=10;i++){
            a.add(i);
        }
        printeach("原来的集合：",a);
        //System.out.println("原来的集合："+a+" ");
        Stream<Integer> stream =a.stream();
        stream= stream.filter(n -> n%2==1);
        List<Integer> result =stream.collect(Collectors.toList());
        printeach("过滤后的集合：",result);
        //System.out.println("过滤后的集合："+result);
    }
    public static void printeach(String message,List list){
        System.out.print(message);
        for (Object o : list) {
            System.out.print(o+" ");
        }
        System.out.println();
    }
}
